﻿from character import *
from buffs import *

def calculateSBDPS(char, debuffs):
    # dict fuer ergebnisse
    res = {}

    # Basiscastzeit
    castTime = 3.0
    castTime = castTime - char.skills["Dunkle Macht"] * 0.1
    
    # Zaubertempo anrechnen
    spellHaste = (char.spellhasterating / 15.7) / 100
    castTime = castTime/(1 + spellHaste)
    res["castTime"] = castTime

    # Spelldmgkoeffizient
    spellcoef = 0.857
    spellcoef += char.skills["Schatten und Flamme"] * 0.04
    # 541-603 dmg, rank 10
    minbasedmg = 541
    maxbasedmg = 603
    basedmg = (minbasedmg + maxbasedmg) /2
    # multiplikative sachen
    mult = 1
    if debuffs["Fluch der Schatten"]:
        mult = 1.1 + 0.01 * debuffs["Verhängnis"]
    if debuffs["Elend"] > 0: mult *= 1 + 0.01 * debuffs["Elend"]
    if debuffs["Schattenwirken"]: mult *= 1.1
    if char.buffs.specials["Succubus opfern"] : mult *= 1.15
    if char.buffs.specials["ISB immer aktiv"] : mult *= 1.20
    if char.buffs.specials["4 Teile T6"] : mult *= 1.06

    bonusDMG = 0
    for key in buffs.spelldamage:
        bonusDMG += buffs.spelldamage[key]
    # Zauberschaden durch Dämonische Ägide und Teufelsrüstung
    if buffs.specials["Teufelsrüstung"]:
        bonusDMG += 100
        if char.skills["Dämonische Ägide"] > 0:
            bonusDMG += char.skills["Dämonische Ägide"] * 10
    #Zauberschaden durch verb. Willenskraftbuff
    spiritDMG = 0
    if char.buffs.specials["Verbesserter Göttlicher Willen"] > 0:
        bonusSpirit = 0
        for key in char.buffs.spirit:
            bonusSpirit += char.buffs.spirit[key]
        # Abzug durch Dämonische Umarmung    
        if char.skills["Dämonische Umarmung"] > 0:
            bonusSpirit *= (1 - char.skills["Dämonische Umarmung"] * 0.01)
        spirit = char.intellect + bonusSpirit
        #10% von SDK
        if char.buffs.specials["Segen der Könige"]:
            spirit *= 1.1
        spiritDMG = spirit * char.buffs.specials["Verbesserter Göttlicher Willen"] * 0.05
    
    
        
    raw_spelldmg = char.spelldamage + bonusDMG + spiritDMG
    eSpelldmg = spellcoef * raw_spelldmg
    # apply + hit
    bonushit = 0
    for key in char.buffs.spellhit:
        bonushit += char.buffs.spellhit[key]
    res["bonushit"] = bonushit
    hit = (83 +
              min(16, (char.spellhitrating/12.615)
                  + bonushit
                  )
              )
    res["hitchance"] = hit
    eDMG = (basedmg + eSpelldmg) * hit/100
    # apply crit
    # 1.701 ist klassencrit wl
    bonusCritChance = 0
    for key in char.buffs.spellcrit:
        bonusCritChance += char.buffs.spellcrit[key]
    res["bonusCritChance"] = bonusCritChance
    
    # Crit durch int
    bonusInt = 0
    for key in char.buffs.intellect:
        bonusInt += char.buffs.intellect[key]

    #Gnomen racial, 5% int
    if char.race == "Gnom":
        bonusInt *= 1.05
    # SDK, 10% int
    if char.buffs.specials["Segen der Könige"]:
        critFromIntellect = (char.intellect + bonusInt) * 1.1 /82
    else:
        critFromIntellect = (char.intellect + bonusInt)/82
    
    critChance= 1.701 \
                + critFromIntellect \
                + char.spellcritrating/22.08 \
                + char.skills["Verwüstung"] \
                + char.skills["Heimzahlen"] \
                + bonusCritChance \
                + debuffs["vergeltersiegel"]
    res["critChance"] = critChance
    critChance /= 100
    if char.skills["Verderben"] == 1:
        if char.specials["metagem"]:
            critMul = 1.09
        else:
            critMul = 1.0
    else:
        if char.special["metagem"]:
            critMul = 0.545
        else:
            critMul = 0.5
    # und drauf
    # effektives crit
    effCritChance = critChance * critMul
    res["effCritChance"] = effCritChance * 100
    
    avgHit = eDMG * mult
    res["avgHit"] = avgHit

    res["avgCrit"] = avgHit * (critMul + 1)
    
    avg= eDMG * (1+effCritChance) * mult
    res["avg"] = avg
    
    res["DPS"] = avg/castTime
    return res

    
    


buffs = buffs(
    specials= {"Succubus opfern" : True,
               "Segen der Könige": True,
               "Alchimistenstein":  True,
               "4 Teile T6": True,
               "ISB immer aktiv": False,
               "Verbessertes Machtwort: Seelenstärke" : 2,
               "Verbesserter Göttlicher Willen": 2,
               "Teufelsrüstung": True,
               },
    spelldamage = {"Zauberöl": 42,
                   "Flask": 70,
                   "Bufffood": 23,
                   "Ikone des Silberwappens": 25.8,
                   "Scharfsinnsanhaenger der Zerschmetterten Sonne": 20},
    spellhit = {"wrath of the air - hit": 3,
                "Inspiring Presence" : 1},
    spellcrit = { "wrath of the air - crit": 3,
                  "moonkin aura": 5},
    intellect = {"Arcane Intellect": 40,
                 "Mal der Wildnis": 14},
    spirit = {"Göttlicher Willen": 50,
              "Bufffood": 20,
              "Mal der Wildnis": 14,
              },
    stamina= {"Mal der Wildnis": 14,
              "Machtwort: Seelenstärke": 79,
              },
    )
                   
                   
                   
debuffs = {}
debuffs['Fluch der Schatten'] = True
debuffs['Verhängnis'] = 3
debuffs['Schattenwirken'] = True
debuffs['Elend'] = 5
debuffs['vergeltersiegel'] = 3

c = character(spelldamage = 1239,
              spellhitrating = 204,
              spellcritrating = 250,
              spellhasterating = 144,
              intellect = 468,
              spirit= 181,
              strength = 52,
              agility = 67,
              stamina = 659,
              buffs = buffs,
              race="Gnom"
              )

r1 = calculateSBDPS(c, debuffs)
c.buffs.specials["ISB immer aktiv"] = True
r2 = calculateSBDPS(c, debuffs)

print """Analyse -- DPS, Schattenblitz
%4d DPS aktuell 
%4d DPS mit ISB aktiv
""" % (r1["DPS"],r2["DPS"])
#keys = result.keys()
#keys.sort()
#for key in keys:
#    print "%s: \t %4.2f" % (key, result[key])


